package com.example.demo_mysql_mybatisplus.util.api.crudFree;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo_mysql_mybatisplus.util.easyexcel.exports.simple_export.SimpleExporter;
import com.example.demo_mysql_mybatisplus.util.auditLog.AuditStrategyEnum;
import com.example.demo_mysql_mybatisplus.util.auditLog.FreeAuditLog;
import com.example.demo_mysql_mybatisplus.util.api.crudFree.dto.FreeEditDto;
import com.example.demo_mysql_mybatisplus.util.api.crudFree.dto.FreeQueryDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Set;

public interface FreeController<T> {
    FreeService<T> service();

    @PostMapping("/free/addOne")
    @FreeAuditLog(AuditStrategyEnum.onlyRecordLog)
    default T addOne(@RequestParam Integer userId, @RequestBody T entity ) {
        return service().addOne(entity);
    }

    @PostMapping("/free/editOne")
    @FreeAuditLog(AuditStrategyEnum.onlyRecordLog)
    default void editOne(@RequestBody T entity) {
        service().editOne(entity);
    }
    @PostMapping("/free/dealDiffLog/editOne")
    @FreeAuditLog(AuditStrategyEnum.recordLogAndDealDifference)
    default void edit4DealDiffLog(@RequestBody T entity) {
        service().editOne(entity);
    }
    @PostMapping("/free/changeFieldValueByIds")
    @FreeAuditLog(AuditStrategyEnum.recordLogAndDealDifference)
    default void changeFieldValueByIds(@RequestBody FreeEditDto reqDto) {
        service().changeFieldValueByIds(reqDto);
    }
    @PostMapping("/free/deleteByIds")
    @FreeAuditLog(AuditStrategyEnum.onlyRecordLog)
    default void deleteByIds(@RequestBody Set<Long> ids) {
        service().deleteByIds(ids);
    }

    @PostMapping("/free/queryByConditions")
    @SimpleExporter()
    default Object queryByConditions(@RequestBody FreeQueryDto reqDto) {
        QueryWrapper<T> qWrapper = service().buildQueryWrapper(reqDto );
        return service().doQuery( reqDto, qWrapper);
    }
/*
{
	"pageNum": 1,
	"pageSize": 2,
	"specialReturnFields": ["id","uniqueKey","name","deptId","operateTime"],
	"bigGroupField":"name",
	"orderBy": {
		"name": "desc",
		"operatorId": "asc"
	},
	"authLimitCodes": ["inCompany","canUse"],
	"equalCondition": {
		"status": 0,
		"typeJson": "{}",
		"uniqueKey": ["cf_test_key_001","cf_test_key_002","cf_test_key_003","cf_test_key_004"]
	},
	"notEqualCondition": {
		"uniqueKey": ["cf_test_key_001","cf_test_key_002","cf_test_key_003","cf_test_key_004"]
	},
	"likeCondition": {
		"name": "cf",
		"uniqueKey": "cf"
	}
}
* */

}

